package com.tgy.基础学习.Thread.线程池;

/**
 * @author 送你一块二向箔
 * @date 2021/11/09 15:47
 */

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 测试线程池
 */
public class ThreadPool {
    public static void main(String[] args) {
        /*
        创建服务，创建线程池
        newFixedThreadPool 参数为：线程池大小

         */
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        /*
        执行
         */
        executorService.execute(new MyThread());
        executorService.execute(()->{for (int i = 0; i < 3; i++) {
            System.out.println("这是线程池的lambda");
        }});
        executorService.execute(new Print()::say);
        /*
        关闭连接
         */
        executorService.shutdown();



/*        new Thread(new MyThread(),"我的线程").start();
        new Thread(()->{
            for (int i = 0; i < 3; i++) {
                System.out.println(Thread.currentThread().getName()+i);
            }
        },"lambda线程").start();*/

    }

}


class Print {
    public void say(){
        System.out.println("方法引用");
    }
}

class MyThread implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i <2; i++) {
            System.out.println(Thread.currentThread().getName()+i);
        }

    }
}
